/**
 * Created by Richard Radlherr.
 * Date: 15.07.2006 18:43
 */

using System;
using System.Collections.Generic;
using CsGL;
using CsGL.OpenGL;
using TagTool.Core;
using TagTool.OpenGL;
using TagTool.GraphicTypes;

namespace TagTool.Nodes.Graphic
{

	public class Rectangle : BaseNode
	{
		InputSlot width;
		InputSlot height;
		InputSlot color;
		
		OutputSlot shape;
		
		public Rectangle() : base()
		{
			Name = "Rectangle";
			width = new InputSlot(this, "Width", 1.0);
			width.ParseCallback = ParseHelper.ParseDouble;
			
			height = new InputSlot(this, "Height", 1.0);
			height.ParseCallback = ParseHelper.ParseDouble;
				
			color = new InputSlot(this, "Color", new Color(1.0, 1.0, 1.0, 1.0));
			Color.ParseCallback = ParseHelper.ParseColor;
			
			shape = new OutputSlot(this, "Shape", typeof(Shape));
			shape.Value = new TagTool.GraphicTypes.Rectangle();
			
		}
		
		public override void Update(Object sender)
		{
			((TagTool.GraphicTypes.Rectangle)shape.Value).Width = (double)width.Value;
			((TagTool.GraphicTypes.Rectangle)shape.Value).Height = (double)height.Value;
			if (((TagTool.GraphicTypes.Rectangle)shape.Value).Color != (Color)color.Value)
			{
				((TagTool.GraphicTypes.Rectangle)shape.Value).Color = (Color)color.Value;
				((TagTool.GraphicTypes.Rectangle)shape.Value).Update();
			}
			CastTrigger();
		}
		
		public override void Initialize() {
			((Shape)shape.Value).Update();
		}
		
		[NodeAttribute(SlotType.Input, Show = true)]
		public InputSlot Width
		{
			get { return width; }
		}

		[NodeAttribute(SlotType.Input, Show = true)]
		public InputSlot Height
		{
			get { return height; }
		}
		
		[NodeAttribute(SlotType.Input, Show = true)]
		public InputSlot Color
		{
			get { return color; }
		}

		[NodeAttribute(SlotType.Output, Show = true)]
		public OutputSlot Shape
		{
			get { return shape; }
		}
		
	}
}
